﻿#region References
using System;
using System.Collections.Generic;
using System.Text;
using Xen;
using Xen.Camera;
using Xen.Graphics;
using Xen.Ex.Graphics2D;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Xen.Ex.Material;
using Xen.Graphics.State;
using Xen.Ex.Graphics;
using Xen.Ex.Graphics.Content;
#endregion

namespace Ness.Engine.Graphics
{
    /// <summary>
    /// Used for debugging light sources
    /// </summary>
    class LightSourceDrawer : IDraw
    {
        private IDraw geometry;
        private Vector3 position;
        private Color lightColour;

        public LightSourceDrawer(Vector3 position, IDraw geometry, Color lightColour)
        {
            this.position = position;
            this.geometry = geometry;
            this.lightColour = lightColour;
        }

        public void Draw(DrawState state)
        {
            state.PushWorldTranslateMultiply(ref position);

            DrawSphere(state);

            state.PopWorldMatrix();
        }

        private void DrawSphere(DrawState state)
        {
            //draw the geometry with a solid colour shader
            if (geometry.CullTest(state))
            {
                Xen.Ex.Shaders.FillSolidColour shader = state.GetShader<Xen.Ex.Shaders.FillSolidColour>();

                shader.FillColour = lightColour.ToVector4();
                shader.Bind(state);

                geometry.Draw(state);
            }
        }

        public bool CullTest(ICuller culler)
        {
            return true;
        }
    }
}
